package cn.edu.swust.adressbook.view;


import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;
import android.widget.Checkable;
import android.widget.LinearLayout;
import android.widget.TextView;

import cn.edu.swust.adressbook.R;
import cn.edu.swust.adressbook.bean.Group;

/**
 * 群组列表
 */

public class GroupItemView extends LinearLayout implements Checkable {

    private TextView mNameText;
    private CheckBox mCheckBox;
    private TextView mNumberText;

    public GroupItemView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);

        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.activity_group_list_item, this, true);

        mCheckBox = (CheckBox) view.findViewById(R.id.checkbox);
        mNameText = (TextView) view.findViewById(R.id.group_name);
        mNumberText = (TextView) view.findViewById(R.id.group_member_count);
    }

    public void setCheckBoxVisibility(boolean visible ){
        if (visible){
            mCheckBox.setVisibility(View.VISIBLE);
        }
        else {
            mCheckBox.setVisibility(View.GONE);
        }
    }

    /**
     *
     * @param group
     */
    public void init(Group group){
        mNameText.setText(group.getName());
        mNumberText.setText(String.valueOf(group.getContactCount()));
    }


    @Override
    public void setChecked(boolean b) {
        mCheckBox.setChecked(b);
    }

    @Override
    public boolean isChecked() {
        return mCheckBox.isChecked();
    }

    @Override
    public void toggle() {
        mCheckBox.toggle();
    }

}

